<template>
  <div>
    <a-menu
      class="mainnav"
      v-model:activeKey="activeKey"
      mode="horizontal"
      @select="selectMenu"
    >
      <a-menu-item :key="'/user/feed'" style="width: 15%">推荐</a-menu-item>
      <a-divider type="vertical" />
      <a-menu-item :key="'/user/art-hot'" style="width: 15%">热门</a-menu-item>
      <a-divider type="vertical" />
      <a-menu-item
        v-if="getLocalToken()"
        :key="'/user/art-follow'"
        style="width: 15%"
        >关注</a-menu-item
      >
      <a-divider type="vertical" />
      <a-input-search
        v-model:value="value"
        :placeholder="defaultsearch"
        style="width: 40%"
        @search="onSearch"
      />
    </a-menu>
    <div class="main_content">
      <router-view></router-view>
    </div>
    <a-back-top />
  </div>
</template>


<script setup>
import { useRouter } from "vue-router";
import { defineComponent, ref } from "vue";
import { get, tip, post, getLocalToken } from "@/common";
const router = useRouter();
const activeKey = ref("");
const selectMenu = ({ item, key, selectedKeys }) => {
  router.push({ path: key });
};

const value = ref("");
const defaultsearch = ref("test");
const getsearchtxt = () => {
  if (window.location.search.split("searchval=")[1]) {
    value.value = window.location.search.split("searchval=")[1];
  } else {
    console.log("n");
  }
};
const onSearch = searchValue => {
  if (searchValue == "") {
    value.value = defaultsearch.value;
    router.push({
      path: "/user/search",
      query: { searchval: defaultsearch.value },
    });
  } else {
    router.push({ path: "/user/search", query: { searchval: searchValue } });
  }
};

getsearchtxt();
</script>

<style>
.mainnav {
  background: #ffffff;
  text-align: center;
  height: auto;
  box-shadow: rgb(182, 182, 182) 2px 2px 2px 2px;
}
.main_content {
  margin-top:50px;
  margin-bottom:50px;
  box-shadow: rgb(182, 182, 182) 2px 2px 2px 2px;
  background: #ffffff;
}
</style>